/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.icee.myth.gm.pipelineFactory;

import com.icee.myth.gm.channelhandler.HttpServerHandlerToGM;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
 *
 * @author yangyi
 */
public class HttpServerToGwPipelineInitializer extends ChannelInitializer<SocketChannel> {

//    final static EventExecutorGroup e1 = new DefaultEventExecutorGroup(4);

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //        // Uncomment the following line if you want HTTPS
//        //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
//        //engine.setUseClientMode(false);
//        //pipeline.addLast("ssl", new SslHandler(engine));

        ch.pipeline().addLast("decoder", new HttpRequestDecoder());
        // Uncomment the following line if you don't want to handle HttpChunks.
       ch.pipeline().addLast("aggregator", new HttpObjectAggregator(1048576));
        ch.pipeline().addLast("encoder", new HttpResponseEncoder());
        // Remove the following line if you don't want automatic content compression.
        //pipeline.addLast("deflater", new HttpContentCompressor());
        ch.pipeline().addLast("chunkedWriter", new ChunkedWriteHandler());

        ch.pipeline().addLast(new HttpServerHandlerToGM());
    }

//    public ChannelPipeline getPipeline() throws Exception {
//        // Create a default pipeline implementation.
//        ChannelPipeline pipeline = pipeline();
//
//        // Uncomment the following line if you want HTTPS
//        //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
//        //engine.setUseClientMode(false);
//        //pipeline.addLast("ssl", new SslHandler(engine));
//
//        pipeline.addLast("decoder", new HttpRequestDecoder());
//        // Uncomment the following line if you don't want to handle HttpChunks.
//        pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
//        pipeline.addLast("encoder", new HttpResponseEncoder());
//        // Remove the following line if you don't want automatic content compression.
//        //pipeline.addLast("deflater", new HttpContentCompressor());
//        pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
//        pipeline.addLast("executor", new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(10, 1048567, 1048567)));
//        pipeline.addLast("handler", new HttpServerHandlerToGM());
//        return pipeline;
//    }

}
